package com.example.fw;

public class ContactObject {
	public String firstname;
	public String lastname;
	public String address;
	public String hometelephone;
	public String mobilelephone;
	public String worktelephone;
	public String email;
	public String email2;
	public String birthday;
	public String birthmonth;
	public String birthyear;
	public String address2;
	public String phone2;
	public String id;
	public String group;
	
	private GroupObject groupObj = null;
	public GroupObject getGroupObj()
	{
		if(groupObj != null) return groupObj;
		if(group != "")
		{
			groupObj = ApplicationManager.getInstance().getGroupHelper().getGroupByName(group);
		}
		return groupObj;
	}
	public void setGroupObj(GroupObject newGroup)
	{
		groupObj = newGroup;
		if(groupObj == null) group = "";
		else group = groupObj.getName();
	}
	
	public String getFirstname() {
		return firstname;
	}
	public String getLastname() {
		return lastname;
	}
	public String getAddress() {
		return address;
	}
	public String getHometelephone() {
		return hometelephone;
	}
	public String getMobilelephone() {
		return mobilelephone;
	}
	public String getWorktelephone() {
		return worktelephone;
	}
	public String getEmail() {
		return email;
	}
	public String getEmail2() {
		return email2;
	}
	public String getBirthday() {
		return birthday;
	}
	public String getBirthmonth() {
		return birthmonth;
	}
	public String getBirthyear() {
		return birthyear;
	}
	public String getGroup() {
		return group;
	}
	public String getAddress2() {
		return address2;
	}
	public String getPhone2() {
		return phone2;
	}
	public String getId() {
		return id;
	}
	public ContactObject setFirstname(String firstname) {
		this.firstname = firstname;
		return this;
	}
	public ContactObject setLastname(String lastname) {
		this.lastname = lastname;
		return this;
	}
	public ContactObject setAddress(String address) {
		this.address = address;
		return this;
	}
	public ContactObject setHometelephone(String hometelephone) {
		this.hometelephone = hometelephone;
		return this;
	}
	public ContactObject setMobilelephone(String mobilelephone) {
		this.mobilelephone = mobilelephone;
		return this;
	}
	public ContactObject setWorktelephone(String worktelephone) {
		this.worktelephone = worktelephone;
		return this;
	}
	public ContactObject setEmail(String email) {
		this.email = email;
		return this;
	}
	public ContactObject setEmail2(String email2) {
		this.email2 = email2;
		return this;
	}
	public ContactObject setBirthday(String birthday) {
		this.birthday = birthday;
		return this;
	}
	public ContactObject setBirthmonth(String birthmonth) {
		this.birthmonth = birthmonth;
		return this;
	}
	public ContactObject setBirthyear(String birthyear) {
		this.birthyear = birthyear;
		return this;
	}
	public ContactObject setGroup(String group) {
		this.group = group;
		groupObj = null;
		return this;
	}
	public ContactObject setAddress2(String address2) {
		this.address2 = address2;
		return this;
	}
	public ContactObject setPhone2(String phone2) {
		this.phone2 = phone2;
		return this;
	}
	public ContactObject setId(String id) {
		this.id = id;
		return this;
	}
	
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((firstname == null) ? 0 : firstname.hashCode());
		
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ContactObject other = (ContactObject) obj;
		if (firstname == null) {
			if (other.firstname != null)
				return false;
		} else if (!firstname.equals(other.firstname))
			return false;
		if (id != null && other.id != null) {
				return id.equals(other.id);
		}
		return true;
	}
	
	@Override
	public String toString() {
		return "Contact [" + firstname + ":" + id + "]";
	}

	
	
}